package com.oracle.controller;

import com.oracle.pojo.Book;
import com.oracle.service.IBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//@RestController
@RequestMapping("/books")
public class BookController {

    @Autowired
    private IBookService bookService;

    @GetMapping
    public List<Book> getAll(){
        return bookService.list();
    }

    @GetMapping("{id}")
    public Book getBookById(@PathVariable Integer id){
        return bookService.getById(id);
    }

    @PutMapping
    public boolean insertBook(@RequestBody Book book){
        return bookService.save(book);
    }

    @DeleteMapping("{id}")
    public boolean deleteBookById(@PathVariable Integer id){
        return bookService.removeById(id);
    }

    @PostMapping
    public boolean updateBook(@RequestBody Book book){
        return bookService.updateById(book);
    }

    /*@GetMapping("{currentPage}/{pageSize}")
    public List<Book> getBooksByPage(@PathVariable Integer currentPage,@PathVariable Integer pageSize){
        return bookService.getPage(currentPage,pageSize).getRecords();
    }*/


}
